//
// Created by Tiany on 2021/6/22.
//二叉树的顺序存储结构实现

#include "SeqBinTree.h"
#include "stdio.h"
//#include "stdlib.h"

//二叉树的创建
PSeqBinTree createEmptyBinTree_seq(int m);

//返回下标为p的结点的父结点的下标
int parent_seq(PSeqBinTree tree, int p) {
    if (p < 0 || p >= tree->n)return -1;
    return (p - 1) / 2;
}

//返回下标为p的结点的左子结点的下标
int leftChild_seq(PSeqBinTree tree, int p){
    if (p < 0 || p >= tree->n)return -1;
    return 2*p+1;
}

//返回下标为p的结点的右子结点的下标
int rightChild_seq(PSeqBinTree tree, int p){
    if (p < 0 || p >= tree->n)return -1;
    return 2*(p+1);
}